package com.doit.hbase.client;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

/**
 * @DATE 2021/12/13/9:31
 * @Author MDK
 * @Version 2021.2.2
 **/

/*
* JDBC
* 1.注册驱动
* 2.获取连接
* 3.获取执行SQL的statement对象
* 4.执行SQL
* 5.如果是查询则封装数据
* 6.关闭资源
* */
public class C01_Demo01 {
    public static void main(String[] args) throws Exception {
        //new HBaseConfiguration();
        // 该方法已过期, 点进去之后查找源码, 看注释上的@link;   静态方法,类名.方法名使用
        //1.自定义配置对象
        Configuration conf = HBaseConfiguration.create();
        //2.连接zookeeper
        conf.set("hbase.zookeeper.quorum","linux01:2181,linux02:2181,linux03:2181");
        //3.获取连接对象
        Connection connection = ConnectionFactory.createConnection(conf);
        //4.获取指定hbase操作指令的对象
        //admin对象  表的DDL语言  Tools  运维的命令  快照  NameSpace(创建表,集群,快照,连接等)
        Admin admin = connection.getAdmin();
        TableName[] tableNames = admin.listTableNames();
        for (TableName tableName : tableNames) {
            byte[] name = tableName.getName();
            System.out.println(new String(name));
        }
        //对表中的数据进行操作
//        conn.getTable(TableName.valueOf("tb_user"));
        //释放连接
        connection.close();
    }
}
